package com.yl.auth.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.entity.Biaodan;
import com.yl.auth.entity.HugongfuwuBean;
import com.yl.auth.service.BiaodanService;
import com.yl.auth.service.HugongfuwuService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @datetime 2023/6/17 11:08
 * @description 类对象
 */
@RestController
@Api(tags = "基础设置-护工服务")
@RequestMapping("/admin/hugong/fuwu")
public class HugongfuwuController {
    @Resource
    private HugongfuwuService hugongfuwuService;
    @Resource
    private BiaodanService biaodanService;

    //护工服务分页查询
    @ApiOperation(value = "全查+分页")
    @GetMapping("/findAll/{page}/{limit}")
    public Result<IPage> findAll(@PathVariable @ApiParam("当前页") Integer page, @PathVariable @ApiParam("总条数") Integer limit) {
        Page page1 = new Page(page, limit);
        QueryWrapper<HugongfuwuBean> queryWrapper = new QueryWrapper<>();
        Page page11 = hugongfuwuService.page(page1, queryWrapper);
        return Result.ok(page11);
    }

    //添加护工服务信息
    @ApiOperation(value = "添加护工服务")
    @PostMapping("/save")
    public Result add(@RequestBody HugongfuwuBean hugongfuwuBean) {
        hugongfuwuService.save(hugongfuwuBean);
        return Result.ok();
    }

    //表单全查
    @ApiOperation(value = "表单全查")
    @GetMapping("/findAllbiaodan")
    public Result findAllbiaodan() {
        List<Biaodan> list = biaodanService.list();
        return Result.ok(list);

    }

    //根据id删除护工服务信息
    @DeleteMapping("/remove/{id}")
    public Result delete(@PathVariable Integer id) {
        hugongfuwuService.removeById(id);
        return Result.ok();
    }

    //根据id查询护工服务
    @ApiOperation(value = "根据id查询护工服务")
    @GetMapping("/get/{id}")
    public Result get(@PathVariable Integer id) {
        HugongfuwuBean byId = hugongfuwuService.getById(id);
        return Result.ok(byId);
    }
    //修改护工服务
    @ApiOperation(value = "修改护工服务")
    @PutMapping ("/update")
    public Result update(@RequestBody HugongfuwuBean hugongfuwuBean) {
        hugongfuwuService.updateById(hugongfuwuBean);
        return Result.ok();
    }

    //任务设置查询全部的护工服务信息
    @ApiOperation(value = "任务设置查询全部的护工服务信息")
    @GetMapping("/findAll")
    public Result findAll() {
        List<HugongfuwuBean> list = hugongfuwuService.list();
        return Result.ok(list);
    }
}
